<?xml version='1.0' encoding='ISO-8859-1' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:body>
        <ui:composition template="/templates/template.xhtml">
            <ui:define name="content">
                <b><h3><h:outputLabel value="Administrer brukere" rendered="#{user.findRole()}"/></h3></b>
                <b><h3><h:outputLabel value="Denne siden har du ikke tilgang til!" rendered="#{not user.findRole()}"/></h3></b>
                <br/>
                <h:form>
                <h:commandLink  action="../protected/chooseGame.xhtml" rendered="#{user.findRole()}">Tilbake</h:commandLink>
               </h:form>
                <br/><br/>
                <h:form>
                    <h:commandButton value="Legg til bruker" action="../protected/addUser.xhtml" rendered="#{user.findRole()}"/><br/>
                    <h:commandButton value="Highscoreliste" action="../protected/highscores.xhtml" rendered="#{user.findRole()}"/>
               </h:form>
                <br/><br/>
                <h:form>
                    <h:dataTable value="#{user.tableUsers}" var="name" styleClass="names"
                                 headerClass="namesHeader" footerClass="namessFooter"
                                 rowClasses="last,first" rendered="#{user.findRole()}">
                        <h:column>
                            <f:facet name="header">Navn</f:facet>
                            <h:outputText value="#{name.name}" rendered="#{not user.newRow(name)}"/>
                            <h:inputText value="#{user.editUser.name}" rendered="#{user.newRow(name)}">
                                <f:validateLength minimum="1"/>
                            </h:inputText>
                        </h:column>
                        <h:column>
                            <f:facet name="header">Brukernavn</f:facet>
                            <h:outputText value="#{name.username}" rendered="#{not user.newRow(name)}"/>
                            <h:inputText value="#{user.editUser.username}" rendered="#{user.newRow(name)}">
                                <f:validateLength minimum="1"/>
                            </h:inputText>
                        </h:column>

                        <h:column>
                            <f:facet name="header">Passord</f:facet>
                            <h:outputText value="#{name.password}" rendered="#{not user.newRow(name)}"/>
                            <h:inputText value="#{user.editUser.password}" rendered="#{user.newRow(name)}">
                                <f:validateLength minimum="1"/>
                            </h:inputText>
                        </h:column>
                        <h:column>
                            <f:facet name="header">Rolle</f:facet>
                            <h:outputText value="#{name.role}" rendered="#{not user.newRow(name)}"/>
                            <h:selectOneMenu value="#{user.editUser.role}" rendered="#{user.newRow(name)}">
                                <f:selectItem itemLabel="elev" itemValue="bruker"/>
                                <f:selectItem itemLabel="Lerer" itemValue="system"/>
                            </h:selectOneMenu>
                            
                        </h:column>
                        <h:column>

                            <h:commandLink action="../protected/getScoreUser.xhtml" actionListener="#{result.setStats(name)}" rendered="#{not user.workingWithNewRow}" style="margin-left: 10px;">
                                <h:graphicImage title="Se poeng" value="/resources/images/les.png"/>
                            </h:commandLink>

                            <h:commandLink action="#{user.changeUser(name)}" rendered="#{not user.workingWithNewRow}">
                                <h:graphicImage title="Endre elev" value="/resources/images/edit.png" />
                            </h:commandLink>

                            <h:commandLink action="#{user.deleteUser(name)}" rendered="#{not user.workingWithNewRow}">
                                <h:graphicImage title="Slett elev" value="/resources/images/delete.png" />
                            </h:commandLink>

                            <h:commandLink action="#{user.confirmInsert()}" rendered="#{user.newRow(name)}">
                                <h:graphicImage value="/resources/images/accept.png" />
                            </h:commandLink>
                            <h:commandLink action="#{user.noEdit(name)}" rendered="#{user.newRow(name)}" immediate="true">
                                <h:graphicImage value="/resources/images/delete.png" />
                            </h:commandLink>
                            
                        </h:column>
                    </h:dataTable>
                </h:form>
            </ui:define>
        </ui:composition>
    </h:body>
</html>